/*
 *Copyright © 2015 HanHai
 *湖北汉海拍卖集团
 *All rights reserved.
 */
package com.hanhai.zrb.backend.web.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hanhai.common.web.controller.BaseController;
import com.hanhai.zrb.api.biz.service.FeedbackService;
import com.hanhai.zrb.backend.admin.model.BackendUser;
import com.hanhai.zrb.backend.util.BackendLoginUtil;
import com.hanhai.zrb.model.user.Feedback;
import com.hanhai.zrb.model.user.dto.FeedbackDto;

@Controller
@RequestMapping("feedback")
public class FeedBackController extends BaseController {
	private final Logger logger = LoggerFactory.getLogger(FeedBackController.class);
	@Resource
	private FeedbackService feedbackService;

	@RequestMapping("index")
	public String index() {
		return "feedback/queryList";
	}

	@RequestMapping("list")
	public void list(FeedbackDto feedbackDto,Integer page,Integer rows,HttpServletResponse response) throws IOException {
		PageInfo pageInfo = feedbackService.searchFeedbackPage(feedbackDto,page,rows);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", pageInfo.getList());
		map.put("total", pageInfo.getTotal());
		String str = JSONObject.toJSONString(map);
		response.getWriter().write(str);
	}
	
	
	@RequestMapping(value="acceptData")
	public void acceptData(Feedback feedback,HttpServletResponse response) throws Exception{
		Map<String, Object> map=new HashMap<String, Object>();
		feedback.setStatus(1);
		try {
			BackendUser user = BackendLoginUtil.getCurrentUser();
			feedback.setAccpUname(user.getLoginName());
        	feedback.setAccpTime(new Date());
			feedbackService.updateByPrimaryKeySelective(feedback);
			map.put("success", true);
			map.put("infoMsg", "当前数据受理成功");
		} catch (Exception e) {
            logger.error("do feedbackService.updateByPrimaryKeySelective(feedback) error",e);
			map.put("success", false);
			map.put("errorMsg", "当前数据受理失败");
		}

		response.getWriter().write(JSONObject.toJSONString(map));
	}
	
}
